<template>
  <van-address-edit
    :area-list="areaList"
    :address-info="address.addressInfo"
    :show-delete="address.editIdx !== -1"
    show-set-default
    show-search-result
    :search-result="searchResult"
    :area-columns-placeholder="['请选择', '请选择', '请选择']"
    @save="onSave"
    @delete="onDelete"
    @change-detail="onChangeDetail"
  />
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import { showToast } from "vant";
import { areaList } from "@vant/area-data";
import { IAddressType, useAddress } from "../../store/address";
const searchResult = ref<any>([]);
// const addressInfo = reactive({
//   //为了测试方便
//   name: "三丰",
//   tel: "17655556666",
//   // province: "重庆",
//   // city: "重庆",
//   // county: "九龙坡",
//   addressDetail: "渝高大厦",
//   areaCode: "500107",
//   isDefault: false,
// });
const address = useAddress();
const emits = defineEmits<{
  (e: "hide-popup"): void;
}>();
const onSave = (info: IAddressType) => {
  console.log(info);
  address.addressAddAct({ ...info });
  emits("hide-popup");
};
const onDelete = () => {
  address.addressDelAct();
  emits("hide-popup");
};
const onChangeDetail = (val: any) => {
  if (val) {
    searchResult.value = [
      {
        name: "黄龙万科中心",
        address: "杭州市西湖区",
      },
    ];
  } else {
    searchResult.value = [];
  }
};
</script>

<style scoped></style>
